<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="需求类别" prop="resultCategory">
        <el-input
          v-model="queryParams.resultCategory"
          placeholder="请输入需求类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术领域" prop="technology">
        <el-input
          v-model="queryParams.technology"
          placeholder="请输入技术领域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item  label="需求人姓名" prop="firstName">
        <el-input
          v-model="queryParams.firstName"
          placeholder="请输入需求人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="需求人ID" prop="firstId">
        <el-input
          v-model="queryParams.firstId"
          placeholder="请输入需求人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人联系电话" prop="firstPhone">
        <el-input
          v-model="queryParams.firstPhone"
          placeholder="请输入负责人联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人身份证号" prop="firstIdnumber">
        <el-input
          v-model="queryParams.firstIdnumber"
          placeholder="请输入负责人身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="enterpriseNumber">
        <el-input
          v-model="queryParams.enterpriseNumber"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人姓名" prop="corporateName">
        <el-input
          v-model="queryParams.corporateName"
          placeholder="请输入法人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人邮箱" prop="corporateEmail">
        <el-input
          v-model="queryParams.corporateEmail"
          placeholder="请输入法人邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人电话" prop="corporatePhone">
        <el-input
          v-model="queryParams.corporatePhone"
          placeholder="请输入法人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人身份证号" prop="corporateNumber">
        <el-input
          v-model="queryParams.corporateNumber"
          placeholder="请输入法人身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业营业执照" prop="businessLicense">
        <el-input
          v-model="queryParams.businessLicense"
          placeholder="请输入企业营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业执照注册地" prop="licenseAddress">
        <el-input
          v-model="queryParams.licenseAddress"
          placeholder="请输入营业执照注册地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业地址" prop="enterpriseAddress">
        <el-input
          v-model="queryParams.enterpriseAddress"
          placeholder="请输入企业地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditState">
        <el-input
          v-model="queryParams.auditState"
          placeholder="请输入审核状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="auditTime">
        <el-date-picker clearable
          v-model="queryParams.auditTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核人姓名" prop="auditName">
        <el-input
          v-model="queryParams.auditName"
          placeholder="请输入审核人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人工号" prop="auditNumber">
        <el-input
          v-model="queryParams.auditNumber"
          placeholder="请输入审核人工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否显示" prop="isShow">
        <el-input
          v-model="queryParams.isShow"
          placeholder="请输入是否显示"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注1" prop="note1">
        <el-input
          v-model="queryParams.note1"
          placeholder="请输入备注1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注2" prop="note2">
        <el-input
          v-model="queryParams.note2"
          placeholder="请输入备注2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注3" prop="note3">
        <el-input
          v-model="queryParams.note3"
          placeholder="请输入备注3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注4" prop="note4">
        <el-input
          v-model="queryParams.note4"
          placeholder="请输入备注4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注5" prop="note5">
        <el-input
          v-model="queryParams.note5"
          placeholder="请输入备注5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注6" prop="note6">
        <el-input
          v-model="queryParams.note6"
          placeholder="请输入备注6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注7" prop="note7">
        <el-input
          v-model="queryParams.note7"
          placeholder="请输入备注7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注8" prop="note8">
        <el-input
          v-model="queryParams.note8"
          placeholder="请输入备注8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注9" prop="note9">
        <el-input
          v-model="queryParams.note9"
          placeholder="请输入备注9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注10" prop="note10">
        <el-input
          v-model="queryParams.note10"
          placeholder="请输入备注10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:demand:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:demand:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:demand:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:demand:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="demandList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="需求名称" align="center" prop="resultName" />
      <el-table-column label="需求类别" align="center" prop="resultCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_result_category" :value="scope.row.resultCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="技术领域" align="center" prop="technology">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cxcy_technology" :value="scope.row.technology"/>
        </template>
      </el-table-column>
      <el-table-column label="成果简介" align="center" prop="resultIntroduction" />
      <el-table-column label="创新点" align="center" prop="innovationPoint" />
      <el-table-column label="成果研究意义" align="center" prop="resultMeaning" />
      <el-table-column label="需求人姓名" align="center" prop="firstName" />
      <el-table-column label="需求人ID" align="center" prop="firstId" />
      <el-table-column label="负责人联系电话" align="center" prop="firstPhone" />
      <el-table-column label="负责人身份证号" align="center" prop="firstIdnumber" />
      <el-table-column label="企业名称" align="center" prop="enterpriseName" />
      <el-table-column label="统一社会信用代码" align="center" prop="enterpriseNumber" />
      <el-table-column label="法人姓名" align="center" prop="corporateName" />
      <el-table-column label="法人邮箱" align="center" prop="corporateEmail" />
      <el-table-column label="法人电话" align="center" prop="corporatePhone" />
      <el-table-column label="法人身份证号" align="center" prop="corporateNumber" />
      <el-table-column label="企业营业执照" align="center" prop="businessLicense" />
      <el-table-column label="营业执照注册地" align="center" prop="licenseAddress" />
      <el-table-column label="企业地址" align="center" prop="enterpriseAddress" />
      <el-table-column label="审核状态" align="center" prop="auditState" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人姓名" align="center" prop="auditName" />
      <el-table-column label="审核人工号" align="center" prop="auditNumber" />
      <el-table-column label="是否显示" align="center" prop="isShow" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:demand:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:demand:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业需求对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="需求名称" prop="resultName">
          <el-input v-model="form.resultName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="需求类别" prop="resultCategory">
          <el-input v-model="form.resultCategory" placeholder="请输入需求类别" />
        </el-form-item>
        <el-form-item label="技术领域" prop="technology">
          <el-input v-model="form.technology" placeholder="请输入技术领域" />
        </el-form-item>
        <el-form-item label="成果简介" prop="resultIntroduction">
          <el-input v-model="form.resultIntroduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创新点" prop="innovationPoint">
          <el-input v-model="form.innovationPoint" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="成果研究意义" prop="resultMeaning">
          <el-input v-model="form.resultMeaning" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="需求人姓名" prop="firstName">
          <el-input v-model="form.firstName" placeholder="请输入需求人姓名" />
        </el-form-item>
        <el-form-item label="需求人ID" prop="firstId">
          <el-input v-model="form.firstId" placeholder="请输入需求人ID" />
        </el-form-item>
        <el-form-item label="负责人联系电话" prop="firstPhone">
          <el-input v-model="form.firstPhone" placeholder="请输入负责人联系电话" />
        </el-form-item>
        <el-form-item label="负责人身份证号" prop="firstIdnumber">
          <el-input v-model="form.firstIdnumber" placeholder="请输入负责人身份证号" />
        </el-form-item>
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="form.enterpriseName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="enterpriseNumber">
          <el-input v-model="form.enterpriseNumber" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="法人姓名" prop="corporateName">
          <el-input v-model="form.corporateName" placeholder="请输入法人姓名" />
        </el-form-item>
        <el-form-item label="法人邮箱" prop="corporateEmail">
          <el-input v-model="form.corporateEmail" placeholder="请输入法人邮箱" />
        </el-form-item>
        <el-form-item label="法人电话" prop="corporatePhone">
          <el-input v-model="form.corporatePhone" placeholder="请输入法人电话" />
        </el-form-item>
        <el-form-item label="法人身份证号" prop="corporateNumber">
          <el-input v-model="form.corporateNumber" placeholder="请输入法人身份证号" />
        </el-form-item>
        <el-form-item label="企业营业执照" prop="businessLicense">
          <el-input v-model="form.businessLicense" placeholder="请输入企业营业执照" />
        </el-form-item>
        <el-form-item label="营业执照注册地" prop="licenseAddress">
          <el-input v-model="form.licenseAddress" placeholder="请输入营业执照注册地" />
        </el-form-item>
        <el-form-item label="企业地址" prop="enterpriseAddress">
          <el-input v-model="form.enterpriseAddress" placeholder="请输入企业地址" />
        </el-form-item>
        <el-form-item label="审核状态" prop="auditState">
          <el-input v-model="form.auditState" placeholder="请输入审核状态" />
        </el-form-item>
        <el-form-item label="审核时间" prop="auditTime">
          <el-date-picker clearable
            v-model="form.auditTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核人姓名" prop="auditName">
          <el-input v-model="form.auditName" placeholder="请输入审核人姓名" />
        </el-form-item>
        <el-form-item label="审核人工号" prop="auditNumber">
          <el-input v-model="form.auditNumber" placeholder="请输入审核人工号" />
        </el-form-item>
        <el-form-item label="是否显示" prop="isShow">
          <el-input v-model="form.isShow" placeholder="请输入是否显示" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" placeholder="请输入备注1" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" placeholder="请输入备注2" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" placeholder="请输入备注3" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" placeholder="请输入备注4" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" placeholder="请输入备注5" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" placeholder="请输入备注6" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" placeholder="请输入备注7" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" placeholder="请输入备注8" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" placeholder="请输入备注9" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" placeholder="请输入备注10" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDemand, getDemand, delDemand, addDemand, updateDemand } from "@/api/project/demand";

export default {
  name: "Demand",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业需求表格数据
      demandList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询企业需求列表 */
    getList() {
      this.loading = true;
      listDemand(this.queryParams).then(response => {
        this.demandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        resultName: null,
        resultCategory: null,
        technology: null,
        resultIntroduction: null,
        innovationPoint: null,
        resultMeaning: null,
        firstName: null,
        firstId: null,
        firstPhone: null,
        firstIdnumber: null,
        enterpriseName: null,
        enterpriseNumber: null,
        corporateName: null,
        corporateEmail: null,
        corporatePhone: null,
        corporateNumber: null,
        businessLicense: null,
        licenseAddress: null,
        enterpriseAddress: null,
        auditState: null,
        auditTime: null,
        auditName: null,
        auditNumber: null,
        isShow: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业需求";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDemand(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业需求";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDemand(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDemand(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除企业需求编号为"' + ids + '"的数据项？').then(function() {
        return delDemand(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/demand/export', {
        ...this.queryParams
      }, `demand_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
